home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / demo1.zoo / demo / icon / walk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-24  |  2.7 KB  |  123 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: walk.c,v 4.1 88/06/21 14:00:13 bianchi Exp $
  9.     $Source: /tmp/mgrsrc/demo/icon/RCS/walk.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /tmp/mgrsrc/demo/icon/RCS/walk.c,v $$Revision: 4.1 $";
  12.  
  13. #include <sys/time.h>
  14. #include <stdio.h>
  15. #include <signal.h>
  16. #include "term.h"
  17.  
  18. #define ICONPATH    "eye"
  19. #define EYES    24
  20. #define CYC    5
  21. #define EYERT   1
  22. #define EYEDN    7
  23. #define EYELF   13
  24. #define EYEUP    19
  25. #define fsleep(x) \
  26.    { \
  27.    struct timeval time; \
  28.    time.tv_sec = 0; \
  29.    time.tv_usec = (x) * 1000; \
  30.    select(0,0,0,0,&time); \
  31.    }
  32. static char *_quit = "\034";
  33.  
  34. int x, y, w, h, i, j, k;
  35. int hsize, vsize;
  36.  
  37. cleanup()
  38. {
  39.     m_pop();
  40.     m_clear();
  41.     exit(0);
  42. }
  43.  
  44. clearit()
  45. {
  46.     get_size(&x, &y, &hsize, &vsize);
  47.     m_clear();
  48. }
  49. main(argc,argv)
  50. char **argv;
  51. {
  52.         register int s = 0;
  53.     int speed = 1;
  54.     int delay = 90;
  55.     char buf[101];
  56.  
  57.     ckmgrterm( *argv );
  58.  
  59.     m_setup(M_FLUSH);
  60.     m_push(P_BITMAP|P_EVENT|P_FLAGS);
  61.     m_setmode(M_ABS);
  62.  
  63.     if (argc>1 && strcmp(argv[1],"-d")==0)
  64.         delay = atoi(argv[1]+1);
  65.  
  66.     if (argc>1 && strcmp(argv[1],"-s")==0)
  67.         speed=0;
  68.  
  69.     signal(SIGINT,cleanup);
  70.     signal(SIGTERM,cleanup);
  71.     signal(SIGQUIT,clearit);
  72.  
  73.     m_setevent(RESHAPE,_quit);
  74.     m_setevent(REDRAW,_quit);
  75.     
  76.     m_func(B_COPY); /* bit copy, so we don't have to erase */
  77.     m_clear(); /* clear the screen */
  78.     m_ttyset();/* no echo */
  79.  
  80.     for (i = 1; i <EYES+1; i++) {
  81.         sprintf(buf, "%s/eye%d", ICONPATH,i);
  82.         if( !m_bitfile(i, buf, &w, &h) ) {
  83.             fprintf( stderr, "cannot download %s.  quit\n", buf );
  84.             exit( 1 );
  85.         }
  86.     }
  87.     m_ttyreset();/* reset echo */
  88.     get_size(&x, &y, &hsize, &vsize);
  89.     while(1)
  90.     {
  91.         m_flush();
  92.         j = EYERT;
  93.         for (i = 2; i < hsize - w; i += speed) {
  94.             m_bitcopyto(i, 2, w, h, 0, 0, 0, j);
  95.             ++j; /* cycle bitmap number */
  96.             if (j > EYERT+CYC) j = EYERT;
  97.             fsleep(delay); /* delay a bit, so we can see animation */
  98.          }
  99.         j = EYEDN;
  100.         for (i = 2; i < vsize - w - 4; i += speed) {
  101.             m_bitcopyto(hsize - w, i, w, h, 0, 0, 0, j);
  102.             ++j;
  103.             if (j > EYEDN+CYC) j = EYEDN;
  104.             fsleep(delay);
  105.         }
  106.         j = EYELF;
  107.         for (i = hsize - w; i > 2; i -= speed) {
  108.             m_bitcopyto(i, vsize - w - 4, w, h, 0, 0, 0, j);
  109.             ++j; /* cycle the other way */
  110.             if (j > EYELF+CYC) j = EYELF;
  111.             fsleep(delay);
  112.         }
  113.         j = EYEUP;
  114.         for (i = vsize - w - 4; i > 2; i -= speed) {
  115.             m_bitcopyto(2, i, w, h, 0, 0, 0, j);
  116.             ++j;
  117.             if (j > EYEUP+CYC) j = EYEUP;
  118.             fsleep(delay);
  119.         }
  120.     }
  121. }
  122.  
  123.